<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h3 id="title"></h3>
  <input type="text" id="username">

  <script>
    // 数据源
    const data = {
      name: '张三'
    }

    // 获取dom中的元素
    const username = document.getElementById('username')
    username.value = data.name
    const title = document.getElementById('title')
    title.textContent = data.name

    /* username.addEventListener('input', function () {
      data.name = this.value
    }) */
    // 箭头函数的如果使用，则注意this的指向问题
    username.addEventListener('input', evt => {
      data.name = evt.target.value
    })



  </script>
</body>

</html>